import {createSlice, createAsyncThunk} from '@reduxjs/toolkit';
import {login} from 'api/login';
// import AsyncStorage from '@react-native-async-storage/async-storage';
export const userSlice = createSlice({
  name: 'user',
  initialState: {
    token: 'd05c4f9f4ead8928ceb5e9894350cfb6',
  },
  reducers: {},
  extraReducers(buildler) {
    buildler.addCase(getToken.fulfilled, (state, action) => {
      state.token = action.payload;
    });
  },
});
export const getToken = createAsyncThunk(
  'user/getToken',
  async (loginForm: {username: string; password: string}) => {
    const {token} = await login(loginForm);    
    // AsyncStorage.setItem('token', token);
    return token;
  },
);
export default userSlice.reducer;
